#include "slave.h"

Slave::Slave() : QObject() {
    ms_frame   = 10;
}

void Slave::startSlave(QString port_name)
{
    if (m_serial.portName() != port_name) {
        m_serial.close();
        m_serial.setPortName(port_name);

        if (!m_serial.open(QIODevice::ReadWrite)) {
            processError(tr("Can't open %1, error code %2")
                             .arg(m_serial.portName()).arg(m_serial.error()));
            return;
        }
    }

   // m_runButton->setEnabled(false);
  //  m_statusLabel->setText(tr("Status: Running, connected to port %1.")
  //                             .arg(m_serialPortComboBox->currentText()));
}

void Slave::readRequest()
{
    if (!m_timer.isActive())
        m_timer.start(ms_frame);
    m_request.append(m_serial.readAll());
}

void Slave::processTimeout()
{
    m_serial.write ("");
  //  m_serial.write(m_responseLineEdit->text().toUtf8());

    // m_trafficLabel->setText(tr("Traffic, transaction #%1:"
    //                            "\n\r-request: %2"
    //                            "\n\r-response: %3")
    //                             .arg(++m_transactionCount).arg(QString::fromUtf8(m_request))
    //                             .arg(m_responseLineEdit->text()));
    m_request.clear();
}


void Slave::processError(const QString &s)
{
  //    m_statusLabel->setText(tr("Status: Not running, %1.").arg(s));
  //  m_trafficLabel->setText(tr("No traffic."));
}
